/**
 * 
 */
package face.unisannio.content;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;

/**
 * @author Fabio Melillo
 *
 */
public class Student {
	
	private String id;
	private String classe;
	private String label,uid;
	private String nome,cognome;
	
	public Student(String nome, String cognome, String classe,
			String label, String uid) {
		super();
		this.classe = classe;
		this.label = label;
		this.nome = nome;
		this.cognome = cognome;
		this.uid=uid;
	}

	public Student(){
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getClasse() {
		return classe;
	}

	public void setClasse(String classe) {
		this.classe = classe;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getCognome() {
		return cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}
	
	public void write(File file, boolean append) throws FileNotFoundException {
		PrintStream ps = new PrintStream(new FileOutputStream(file,append));
		ps.println(nome);
		ps.println(cognome);
		ps.println(classe);
		ps.println(label);
		ps.println(uid);
		ps.println("###");
	}
	
	public static ArrayList<Student> read(File file) throws FileNotFoundException {
		ArrayList<Student> students = new ArrayList<Student>();
		String nome,cognome,classe,label,uid;
		BufferedReader br = new BufferedReader(new InputStreamReader(
				new FileInputStream(file)));

		try {
			nome = br.readLine();
			cognome = br.readLine();
			classe = br.readLine();
			label = br.readLine();
			uid = br.readLine();
			br.readLine();
			while (label != null){
				students.add(new Student(nome, cognome, classe, label, uid));
				nome = br.readLine();
				cognome = br.readLine();
				classe = br.readLine();
				label = br.readLine();
				uid = br.readLine();
				br.readLine();
			}
		} catch (IOException e) {
			return students;
		}
		return students;
	}
	
}
